﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
 
namespace StuEdu.Web.StuBaseInfo
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					int stuId=(Convert.ToInt32(Request.Params["id"]));
					ShowInfo(stuId);
				}
			}
		}
			
	private void ShowInfo(int stuId)
	{
		StuEdu.BLL.StuBaseInfo bll=new StuEdu.BLL.StuBaseInfo();
		StuEdu.Model.StuBaseInfo model=bll.GetModel(stuId);
		this.lblstuId.Text=model.stuId.ToString();
		this.txtstuNo.Text=model.stuNo.ToString();
		this.txtmicStuNo.Text=model.micStuNo.ToString();
		this.txtstuName.Text=model.stuName;
		this.chkstuSex.Checked=model.stuSex;
		this.txtstuBirth.Text=model.stuBirth.ToString();
		this.txtstuNativePlace.Text=model.stuNativePlace;
		this.txtstuHomeTel.Text=model.stuHomeTel;

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(!PageValidate.IsNumber(txtstuNo.Text))
			{
				strErr+="stuNo格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtmicStuNo.Text))
			{
				strErr+="micStuNo格式错误！\\n";	
			}
			if(this.txtstuName.Text.Trim().Length==0)
			{
				strErr+="stuName不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtstuBirth.Text))
			{
				strErr+="stuBirth格式错误！\\n";	
			}
			if(this.txtstuNativePlace.Text.Trim().Length==0)
			{
				strErr+="stuNativePlace不能为空！\\n";	
			}
			if(this.txtstuHomeTel.Text.Trim().Length==0)
			{
				strErr+="stuHomeTel不能为空！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int stuId=int.Parse(this.lblstuId.Text);
			int stuNo=int.Parse(this.txtstuNo.Text);
			int micStuNo=int.Parse(this.txtmicStuNo.Text);
			string stuName=this.txtstuName.Text;
			bool stuSex=this.chkstuSex.Checked;
			DateTime stuBirth=DateTime.Parse(this.txtstuBirth.Text);
			string stuNativePlace=this.txtstuNativePlace.Text;
			string stuHomeTel=this.txtstuHomeTel.Text;


			StuEdu.Model.StuBaseInfo model=new StuEdu.Model.StuBaseInfo();
			model.stuId=stuId;
			model.stuNo=stuNo;
			model.micStuNo=micStuNo;
			model.stuName=stuName;
			model.stuSex=stuSex;
			model.stuBirth=stuBirth;
			model.stuNativePlace=stuNativePlace;
			model.stuHomeTel=stuHomeTel;

			StuEdu.BLL.StuBaseInfo bll=new StuEdu.BLL.StuBaseInfo();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
